package com.qqtech.qquan.user.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.common.annotation.VisitAnnt;
import com.qqtech.core.common.enums.RespEnum;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.user.enums.UserPrivacyTypeDictEnum;
import com.qqtech.qquan.user.model.UserPrivacy;
import com.qqtech.qquan.user.model.UserPrivacyQuery;
import com.qqtech.qquan.user.model.UserPrivacyVo;
import com.qqtech.qquan.user.service.UserPrivacyService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/user/privacy")
public class UserPrivacyController extends BaseWebController<UserPrivacy, UserPrivacyQuery> {
	@Resource
	private UserPrivacyService userPrivacyService;

	@Override
	protected BaseService<UserPrivacy> getBaseService() {
		return userPrivacyService;
	}

	/**
	 * 我-获取隐私设置
	 * 
	 * @param map
	 * @return
	 */
	@VisitAnnt(type = RespEnum.LOGIN)
	@RequestMapping(value = "/get")
	@ResponseBody
	public Result get() {
		Result result = new Result();
		Integer curUserId = super.getUserId();
		UserPrivacyQuery userPrivacyQuery = new UserPrivacyQuery();
		userPrivacyQuery.setUserId(curUserId);
		userPrivacyQuery.setType(UserPrivacyTypeDictEnum.COMMUNITY_NEIGHBOR.getCode());
		UserPrivacyVo cNeighborVo = userPrivacyService.getOne(userPrivacyQuery, new PageOrder());
		result.put("cNeighborVo", cNeighborVo);
		return result;
	}

	/**
	 * 我-添加隐私
	 * 
	 * @param map
	 * @return
	 */
	@VisitAnnt(type = RespEnum.LOGIN)
	@RequestMapping(value = "/create")
	@ResponseBody
	public Result create(@RequestBody UserPrivacyVo userPrivacyVo) {
		Result result = new Result();
		Integer curUserId = super.getUserId();
		userPrivacyVo.setUserId(curUserId);
		Integer id=userPrivacyService.insert(userPrivacyVo);
		userPrivacyVo.setId(id);
		result.put("userPrivacyVo", userPrivacyVo);
		return result;
	}

	/**
	 * 我-添加隐私
	 * 
	 * @param map
	 * @return
	 */
	@VisitAnnt(type = RespEnum.LOGIN)
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Result delete(@RequestBody UserPrivacyVo userPrivacyVo) {
		Result result = new Result();
		Integer curUserId = super.getUserId();
		userPrivacyVo.setUserId(curUserId);
		UserPrivacyVo delUserPrivacyVo = userPrivacyService.getOne(userPrivacyVo, new PageOrder());
		if (null != delUserPrivacyVo) {
			userPrivacyService.delete(delUserPrivacyVo);
		}
		return result;
	}
}
